package mysql

import "gorm.io/gorm"

// 订单表
type Order struct {
	gorm.Model
	UserId  int32   `gorm:"column:user_id;type:int(11);not null;comment:用户ID"`
	OrderSn string  `gorm:"column:order_sn;type:varchar(100);not null;comment:订单编号"`
	Status  int32   `gorm:"column:status;type:int(11);not null;comment:订单状态"`
	PayType int32   `gorm:"column:pay_type;type:int(11);not null;comment:支付方式"`
	PayTime int32   `gorm:"column:pay_time;type:int(11);not null;comment:支付时间"`
	Total   float32 `gorm:"column:total;type:decimal(10,2);not null;comment:订单总金额"`
}

// 订单商品表
type OrderGoods struct {
	gorm.Model
	UserId       int32   `gorm:"column:user_id;type:int(11);not null;comment:用户ID"`
	OrderId      int32   `gorm:"column:order_id;type:int(11);not null;comment:订单ID"`
	GoodsId      int32   `gorm:"column:goods_id;type:int(11);not null;comment:商品ID"`
	GoodsName    string  `gorm:"column:goods_name;type:varchar(100);not null;comment:商品名称"`
	OrderGoodsSn string  `gorm:"column:order_goods_sn;type:varchar(100);not null;comment:订单商品编号"`
	GoodsPrice   float32 `gorm:"column:goods_price;type:decimal(10,2);not null;comment:商品价格"`
	GoodsNum     int32   `gorm:"column:goods_num;type:int(11);not null;comment:商品数量"`
}

// 创建订单
func (o *Order) CreateOrder() error {
	return mysqlClient.Create(&o).Error
}

// 创建订单商品表
func (og *OrderGoods) CreateOrderGoods() error {
	return mysqlClient.Create(&og).Error
}
